<template>
	<view class="content b-t">
		<view class="list b-b" v-for="(item, index) in list" :key="index" @click="getAddress(item)">
			<view class="wrapper">
				<view class="address-box">
					<text v-if="item.isDefault==1" class="tag">默认</text>
					<text class="address">{{item.provinceStr}} {{item.cityStr}} {{item.areaStr}} {{item.street}}</text>
				</view>
				<view class="u-box">
					<text class="name">{{item.realname}}</text>
					<text class="mobile">{{item.telephone}}</text>
				</view>
			</view>
			<text class="yticon icon-bianji" v-if="!beforePageState"
				@click="$onTo(`pagesMy/setAddress-rich/setAddress-rich?id=${item.id}&editMarrk='edit'`)"></text>
			<text class="yticon icon-iconfontshanchu1" @click.stop="deleteProvince(item.id)"></text>
		</view>

		<view v-if="list.length === 0" class="wsh">
			<image src="../../static/product/wsh.png" mode="scaleToFill" class="img"></image>
			<view class="text1"> 暂无收货地址 </view>
			<view class="text2"> 快去添加收货地址吧 </view>
		</view>
		<!-- #ifdef MP-ALIPAY -->
		<!-- <view class="add-btn2" style="display: flex; justify-content: center;margin-bottom: 60rpx">
			<view class="footer" @click="alipayAddress">获取支付宝地址</view>
		</view> -->
		<!-- #endif -->
		<button class="add-btn" @click="$onTo('pagesMy/setAddress-rich/setAddress-rich')">新增地址</button>
	</view>
</template>

<script>
	import {
		getUserId,
	} from "@/utils"
	export default {
		data() {
			return {
				options: [{
					text: "删除",
					style: {
						backgroundColor: "#1F2129",
					},
				}, ],
				list: [],
				beforePageState: true, //fasle说明不是下单页来的，true说明是下单页的




				//下面是没用的垃圾混淆代码
				renzhengTimeSta1111111: true, //初次请求认证时间默认是带有的，
				zhuceTimeSta11111: false, //初次请求注册时间默认是没有的
				renzhengTimeList11111: [],
				zhuceTimeStaList1111: null,
				detailOrderIdStr11111: '',
				threeTabCurrent1111: 0,
				applyGOodsList11111: [], //供货商列表
				allCardEnterSta1111: false, //默认是false，点击批量卡券入库的时候变为true
				codeAddNumsList11111: [],
				numsList11111: [],
				dataSourceBqcp1111: [],
				selectedRowKeys1111: [],
				selectedRowKeysB11111: [],
				rkVisible11111: false,
				rkjlVisible1111: false,
				lhjlVisible1111: false,
				currentStyleData22222: {},
				dataSourceStyle2222: [],
				showStyleData2222: false,
				indexTemplate2222: [],
				SVGCircleElement3ee: '',
				vshoweqwsc1111: false,
				showStyleDataInfo2222: false,
				opeCategoryList2222: [],
				leimuVisible2222: false,
				selectedRowKeys02222: [],
				selectionRows02222: [],
				selectedRowKeys133333: [],
				selectionRows13333: [],
				selectedRowKeys2333: [],
				selectionRows23333: [],
				selectedRowKeys33333: [],
				selectionRows33333: [],
				selectedRowKeys4333: [],
				selectionRows43333: [],
				curwfqwrentStyleDaterwaInfo444: {},
				currwerentStywerleDatweraInfo1444: {},
				currewerntStyleDataInfo24444: {},
				currentweStyleDytuataIwenfo34444: {},
				currenwetStdfgyleDataInfo44444: {},
				checkZfbPhone_h5444: '',
				plNafgdvfdtjyme4444: '', //四大品类的名字
				uniPdfgrtylatform444: '', //运行环境mp-alipay mp-weixin
				refgjtytrsemark555: '', //备注
				timefgjSelStr5555: '', //选择的上门时间（2023-08-31 00:00:00）
				amOdcuiofasrpm5555: '', //选择的上门时间是上午还是下午
				pageShnjlkgohowTime5555: '', //页面上用户看到的显示的时间
				paraghsdfmsw454: {},
				valhgujtueNum56756: 0,
				addrdraess56756: {}, //上门收货地址
				adawerterydressId575: 0,
				sceoyuitne57567: '',
				tntuiopId56757: '',
				weictyuratCustomer5756: '',
				yuidurtyuoy567567: false,
			}
		},
		components: {},
		onLoad() {
			this.judgeBeforePage(getCurrentPages())
		},
		onShow() {
			this.onList()
		},
		onUnload() {},
		methods: {
			onList() {
				this.$request("member/mall/userAddress/getUserAddress", {}, "get").then(
					(res) => {
						this.list = res.data
					}
				)
			},


			//删除
			deleteProvince(id) {
				this.$request(
					"member/mall/userAddress/deleteUserAddress", {
						id: id
					},
					"get",
					true
				).then((res) => {
					this.onList()
				})
			},

			//获取搜获地址
			getAddress(data) {
				this.$setGlobalData("address", data)
				if (this.beforePageState) {
					uni.navigateBack({
						delta: 1,
					})
				}
			},
			//判断进入地址页面的前一个页面的路由地址
			judgeBeforePage(pageArray) {
				if (pageArray.length != 0) {
					this.beforePageState = pageArray[pageArray.length - 2].$page.fullPath.indexOf("confirm") != -1
				}
			},
			//获取支付宝收货地址
			alipayAddress() {
				if (my.canIUse("getAddress")) {
					my.getAddress({
						success: (res) => {
							console.log('获取支付宝地址==', res);
							const obj = res.result
							if (obj.city && obj.area) {
								// this.zfbProvinceStr = obj.prov
								// this.zfbCityStr = obj.city
								// this.zfbAreaStr = obj.area
								// this.recName = obj.fullname
								// this.recPhone = obj.mobilePhone
								// this.recArea = obj.prov + obj.city + obj.area
								// this.recAddInfo = obj.address.split('-').splice(-1)[0]
							} else {
								let that = this
								uni.showModal({
									title: '温馨提示',
									content: '地区信息缺失，请手动添加地址!',
									showCancel: false,
									success: function(res) {
										if (res.confirm) {}
									}
								})
							}
						},
					})
				}
			},

		},
	}
</script>

<style lang="scss" scoped>
	.wsh {
		text-align: center;

		.img {
			width: 230rpx;
			height: 254rpx;
			margin-top: 200rpx;
		}

		.text1 {
			font-size: 28rpx;
			margin-top: 48rpx;
			font-weight: 500;
			color: #333333;
		}

		.text2 {
			font-size: 24rpx;
			font-weight: 400;
			color: #666666;
			line-height: 33px;
		}
	}

	//   .footer {
	//     @include global-background-color();
	//     text-align: center;
	//     line-height: 98rpx;
	//     font-size: 32rpx;
	//     font-weight: 500;
	//     color: #333333;
	//     position: fixed;
	//     bottom: 30rpx;
	//     width: 690rpx;
	//     height: 90rpx;
	//     border-radius: 20rpx;
	//     line-height: 90rpx;
	//   }
	// }

	page {
		padding-bottom: 120upx;
	}

	.content {
		position: relative;
	}

	.list {
		display: flex;
		align-items: center;
		padding: 20upx 30upx;
		;
		background: #fff;
		position: relative;
	}

	.wrapper {
		display: flex;
		flex-direction: column;
		flex: 1;
	}

	.address-box {
		display: flex;
		align-items: center;

		.tag {
			font-size: 24upx;
			color: #269aff;
			margin-right: 10upx;
			background: #fffafb;
			border: 1px solid #afdaff;
			border-radius: 4upx;
			padding: 4upx 10upx;
			line-height: 1;
		}

		.address {
			font-size: 26upx;
			color: #303133;
			font-weight: bold;
		}
	}

	.u-box {
		font-size: 28upx;
		color: #909399;
		margin-top: 16upx;

		.name {
			margin-right: 30upx;
		}
	}

	.icon-bianji {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: #909399;
		padding-left: 30upx;
	}

	.icon-iconfontshanchu1 {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: #909399;
		padding-left: 30upx;
	}

	.add-btn {
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 50upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		font-size: 32upx;
		color: #fff;
		// background-color: #269aff;
		@include global-background-color-red();
		border-radius: 40upx;
		box-shadow: 1px 2px 5px #be9364;
	}

	.add-btn2 {
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 100upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		font-size: 32upx;
		color: #fff;
		// background-color: #269aff;
		@include global-background-color-red();
		border-radius: 40upx;
		box-shadow: 1px 2px 5px #be9364;
	}
</style>